package com.mosband.genecharts;

import com.alibaba.fastjson.JSON;
import com.mosband.genecharts.comm.Cons;
import com.mosband.genecharts.util.EchartsUtil;
import com.mosband.genecharts.util.FreemarkerUtil;

import java.util.HashMap;

public class Test {
    public static void main(String[] args) throws Exception {

        String ftlName = "line";
//        String ftlName = "sandiantu";
//        String ftlName = "zhuzhuangtu";
//        String ftlName = "bingtu";
//        String ftlName = "zhuzhexiantu";
//        String ftlName = "biaoqianxianshi";
        // 变量
        String title = "水果";
        String[] categories = new String[] { "苹果", "香蕉", "西瓜" };
        int[] values = new int[] { 3, 2, 1 };

        // 模板参数
        HashMap<String, Object> datas = new HashMap<>();
        datas.put("categories", JSON.toJSONString(categories));
        datas.put("values", JSON.toJSONString(values));
        datas.put("title", title);

        // 生成option字符串
        String option = FreemarkerUtil.generateString(ftlName+".ftl", "", datas);
        System.out.println(option);

        // 根据option参数
        String base64 = EchartsUtil.generateEchartsBase64(option,null,null);

        System.out.println("BASE64:" + base64);
        EchartsUtil.generateImage(base64, Cons.getPathOutPath(Cons.path_project,ftlName));
    }


}
